home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 151-175 / disk_166 / stevie / source / updatenextscreen.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  139 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. /*
  12.  * updateNextscreen() 
  13.  *
  14.  * Based on the current value of Topchar, transfer a screenfull of stuff from
  15.  * Filemem to Nextscreen, and update Botchar. 
  16.  */
  17.  
  18. void
  19. updateNextscreen()
  20. {
  21.     int             row, col;
  22.     register char  *screenp = Nextscreen;
  23.     LPTR            memp;
  24.     LPTR            save;    /* save pos. in case line won't fit */
  25.     register char  *endscreen;
  26.     char           *nextrow;
  27.     char            extra[16];
  28.     int             nextra = 0;
  29.     char            c;
  30.     int             n;
  31.     int             done;
  32.     int             srow;    /* starting row of the current line */
  33.  
  34.     MustRedrawLine = FALSE;
  35.     MustRedrawScreen = TRUE;
  36.  
  37.     save = memp = *Topchar;
  38.  
  39.     /* The number of rows shown is Rows-1. */
  40.     /* The last line is the status/command line. */
  41.     endscreen = &screenp[(Rows - 1) * Columns];
  42.  
  43.     srow = done = row = col = 0;
  44.     while (screenp < endscreen && !done) {
  45.  
  46.     /* Get the next character to put on the screen. */
  47.  
  48.     /*
  49.      * The 'extra' array contains the extra stuff that is inserted to
  50.      * represent special characters (tabs, and other non-printable stuff.
  51.      * The order in the 'extra' array is reversed. 
  52.      */
  53.  
  54.     if (nextra > 0)
  55.         c = extra[--nextra];
  56.     else {
  57.         c = gchar(&memp);
  58.         if (inc(&memp) == -1)
  59.         done = 1;
  60.         /*
  61.          * when getting a character from the file, we may have to turn it
  62.          * into something else on the way to putting it into
  63.          * 'Nextscreen'. 
  64.          */
  65.         if (c == TAB && !P(P_LS)) {
  66.         strcpy(extra, "        ");
  67.         /* tab amount depends on current column */
  68.         nextra = ((P(P_TS) - 1) - col % P(P_TS));
  69.         c = ' ';
  70.         } else if (c == NUL && P(P_LS)) {
  71.         extra[0] = NUL;
  72.         nextra = 1;
  73.         c = '$';
  74.         } else if ((n = chars[c].ch_size) > 1) {
  75.         char           *p;
  76.         nextra = 0;
  77.         p = chars[c].ch_str;
  78.         /* copy 'ch-str'ing into 'extra' in reverse */
  79.         while (n > 1)
  80.             extra[nextra++] = p[--n];
  81.         c = p[0];
  82.         }
  83.     }
  84.  
  85.     if (c == NUL) {
  86.         srow = ++row;
  87.         /*
  88.          * Save this position in case the next line won't fit on the
  89.          * screen completely. 
  90.          */
  91.         save = memp;
  92.         /* get pointer to start of next row */
  93.         nextrow = &Nextscreen[row * Columns];
  94.         /* blank out the rest of this row */
  95.         while (screenp != nextrow)
  96.         *screenp++ = ' ';
  97.         col = 0;
  98.         continue;
  99.     }
  100.     if (col >= Columns) {
  101.         row++;
  102.         col = 0;
  103.     }
  104.     /* store the character in Nextscreen */
  105.     *screenp++ = c;
  106.     col++;
  107.     }
  108.     /*
  109.      * If we didn't hit the end of the file, and we didn't finish the last
  110.      * line we were working on, then the line didn't fit. 
  111.      */
  112.     if (!done && c != NUL) {
  113.     /*
  114.      * Clear the rest of the screen and mark the unused lines. 
  115.      */
  116.     screenp = &Nextscreen[srow * Columns];
  117.     while (screenp < endscreen)
  118.         *screenp++ = ' ';
  119.     for (; srow < (Rows - 1); srow++)
  120.         Nextscreen[srow * Columns] = '@';
  121.     *Botchar = save;
  122.     return;
  123.     }
  124.     /* make sure the rest of the screen is blank */
  125.     while (screenp < endscreen)
  126.     *screenp++ = ' ';
  127.     /* put '~'s on rows that aren't part of the file. */
  128.     if (col != 0)
  129.     row++;
  130.     while (row < Rows) {
  131.     Nextscreen[row * Columns] = '~';
  132.     row++;
  133.     }
  134.     if (done)            /* we hit the end of the file */
  135.     *Botchar = *Fileend;
  136.     else
  137.     *Botchar = memp;
  138. }
  139.